<template>
  <div>
    <el-dialog
      :title="title"
      :width="dialogWidth"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :visible.sync="visible"
    >
      <div
        slot="footer"
        class="dialog-footer"
        v-if="activeName =='first'"
      >
        <el-button
          type="primary"
          size="small"
          style="width:70px;"
          @click="xuqian"
          icon="el-icon-connection"
          v-if="inputForm.contractStatus==1 && inputForm.contractTypeId==0"
        >续签</el-button>
        <el-button
          type="primary"
          size="small"
          style="width:70px;"
          icon="el-icon-edit-outline"
          @click="dialogSigned=true"
          v-if="inputForm.contractStatus==0"
        >已签</el-button>
        <el-button
          type="primary"
          size="small"
          style="width:70px;"
          icon="el-icon-link"
          v-if="inputForm.contractStatus==1 && inputForm.contractTypeId!=1"
          @click="dialogTermination = true"
        >终止</el-button>
        <el-button
          icon="el-icon-edit-outline"
          type="primary"
          size="small"
          style="width:90px;"
          v-if="((inputForm.contractStatus==4 && !inputForm.refundNumber)||inputForm.contractStatus==3) && inputForm.contractTypeId==0"
          @click="dialogBackMoney = true"
        >退保证金</el-button>
      </div>
      <el-form
        :model="inputForm"
        ref="inputForm"
        v-loading="loading"
        :class="method==='view'?'readonly':''"
      >
        <el-row :gutter="15">
          <el-col :span="8">
            <el-form-item
              label="合同编号:"
              prop="projectId"
            >
              <label style="font-size:18px;">{{inputForm.contractNumber}}</label>
              <!--<el-input v-model="inputForm.contractNumber"></el-input>-->
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="合同总金额(元):"
              prop="projectId"
            >
              <label style="color:red;font-size:18px;">{{inputForm.sumMoney}}</label>
              <!--<el-input v-model="inputForm.taxpayerNumber"></el-input>-->
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="合同状态:"
              prop="projectId"
            >
              <label style="font-size:18px;">{{inputForm.contractStatus | GetcontractStatus(contractStatus)}}</label>
              <!--<el-input v-model="inputForm.contractStatus"></el-input>-->
            </el-form-item>
          </el-col>
          <!--tab 详情 附件-->
          <el-col>
            <el-tabs
              v-model="activeName"
              @tab-click="handleClick"
            >
              <el-tab-pane
                label="详情"
                name="first"
              >
                <div style="width:100%;">
                  <!--合同信息-->
                  <div style="width:100%;">
                    <div style="width:100%;font-size:18px;border-bottom:1px double #ddd; line-height:40px;">合同信息</div>
                    <div style="width:100%;margin-top:20px;">
                      <el-col :span="12">
                        <el-form-item
                          label="合同分类:"
                          prop="contractTypeId"
                          label-width="140px"
                        >
                          <el-select
                            :disabled="method==='view'"
                            v-model="inputForm.contractTypeId"
                            placeholder="请选择"
                            clearable
                            style="width:100%"
                          >
                            <el-option
                              v-for="item in contractTypeList"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value"
                            >
                            </el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId!=2"
                      >
                        <el-form-item
                          label="房产类型:"
                          prop="projectBuildingId"
                          label-width="130px"
                        >
                          <el-select
                            :disabled="method==='view'"
                            v-model="inputForm.buildingType"
                            placeholder="请选择"
                            style="width:100%"
                          >
                            <el-option
                              v-for="item in proBuildTypeList"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value"
                            >
                            </el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId!=2"
                      >
                        <el-form-item
                          label="关联房产编号:"
                          prop="companyId"
                          label-width="140px"
                        >
                          <el-input
                            :disabled="method==='view'"
                            v-model="inputForm.ctContractProject"
                            placeholder="请输入"
                            style="width:100%;"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item
                          label="公司名称:"
                          prop="companyId"
                          label-width="130px"
                        >
                          <el-select
                            :disabled="method==='view'"
                            v-model="inputForm.companyId"
                            placeholder="请选择"
                            style="width:100%"
                          >
                            <el-option
                              v-for="item in companyNameList"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value"
                            >
                            </el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId==1 && inputForm.contractTypeId!=2"
                      >
                        <el-form-item
                          label="产权人:"
                          prop="taxpayerNumber"
                          label-width="140px"
                        >
                          <el-input
                            :disabled="method==='view'"
                            v-model="inputForm.belonger"
                            placeholder="请输入"
                            style="width:100%;"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item
                          label="联系人:"
                          prop="contactUserName"
                          label-width="130px"
                        >
                          <el-input
                            :disabled="method==='view'"
                            v-model="inputForm.contactUserName"
                            placeholder="请输入"
                            style="width:100%;"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item
                          label="联系方式:"
                          prop="contactUserPhone"
                          label-width="140px"
                        >
                          <el-input
                            :disabled="method==='view'"
                            v-model="inputForm.contactUserPhone"
                            placeholder="请输入"
                            style="width:100%;"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId!=1 && inputForm.dateall"
                      >
                        <el-form-item
                          label="租赁起止日期:"
                          prop="rentStartTime"
                          label-width="140px"
                        >
                          <el-input
                            :disabled="method==='view'"
                            v-model="inputForm.dateall"
                            placeholder="请输入"
                            style="width:100%;"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId!=1 && inputForm.contractTypeId!=2"
                      >
                        <el-form-item
                          label="优惠时间(月):"
                          prop="discountStartTime"
                          label-width="140px"
                        >
                          <el-input
                            :disabled="method==='view'"
                            v-model="inputForm.discountTime"
                            placeholder="请输入"
                            style="width:100%;"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId==2"
                      >
                        <el-form-item
                          label="位置:"
                          prop="advertisingLocation"
                          label-width="130px"
                        >
                          <el-input
                            :disabled="method==='view'"
                            v-model="inputForm.advertisingLocation"
                            placeholder="请输入位置"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId==2"
                      >
                        <el-form-item
                          label="数量:"
                          label-width="180px"
                          prop="advertisingCount"
                        >
                          <el-input
                            :disabled="method==='view'"
                            v-model="inputForm.advertisingCount"
                            placeholder="请输入数量"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId==2"
                      >
                        <el-form-item
                          label="长:"
                          prop="advertisingLength"
                          label-width="130px"
                        >
                          <el-input
                            :disabled="method==='view'"
                            v-model="inputForm.advertisingLength"
                            placeholder="请输入长"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId==2"
                      >
                        <el-form-item
                          label="宽:"
                          prop="advertisingWidth"
                          label-width="180px"
                        >
                          <el-input
                            :disabled="method==='view'"
                            v-model="inputForm.advertisingWidth"
                            placeholder="请输入宽"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId==2"
                      >
                        <el-form-item
                          label="类型:"
                          prop="advertisingType"
                          label-width="130px"
                        >
                          <el-select
                            :disabled="method==='view'"
                            style="width:100%"
                            v-model="inputForm.advertisingType"
                            placeholder="请选择类型"
                          >
                            <el-option
                              v-for="(item,index) in advertisingTypeOption"
                              :key="index"
                              :label="item.label"
                              :value="item.value"
                            ></el-option>
                          </el-select>
                          <!-- <el-input
                    @change="getAllTotoalMoney"
                    v-model="inputForm.advertisingType"
                    placeholder="请输入面积"
                  ></el-input> -->
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId==2"
                      >
                        <el-form-item
                          label="面积(㎡):"
                          prop="advertisingArea"
                          label-width="180px"
                        >
                          <el-input
                            :disabled="method==='view'"
                            v-model="inputForm.advertisingArea"
                            placeholder="请输入面积"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId==2"
                      >
                        <el-form-item
                          label-width="140px"
                          label="租金单价(元/㎡/月):"
                          prop="advertisingUnitPrice"
                        >
                          <el-input
                            :disabled="method==='view'"
                            v-model="inputForm.advertisingUnitPrice"
                            placeholder="输入租金单价(元/㎡/月):"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId==2"
                      >
                        <el-form-item
                          label-width="180px"
                          label="租金总额(元):"
                          prop="contractTotalAmount"
                        >
                          <el-input
                            v-model="inputForm.contractTotalAmount"
                            disabled
                            style="width:100%;"
                            placeholder="输入租金总额(元)"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId==2"
                      >
                        <el-form-item
                          label="优惠价格(元):"
                          label-width="140px"
                        >
                          <el-input
                            style="width:100%;"
                            :disabled="method==='view'"
                            v-model="inputForm.advertisingPreferentialPrice"
                            placeholder="输入 优惠价格(元)"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractStatus!=0"
                      >
                        <el-form-item
                          label="签订日期:"
                          label-width="140px"
                        >
                          <el-date-picker
                            :disabled="method==='view'"
                            style="width: 100%;"
                            v-model="inputForm.signDate"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择日期时间"
                          >
                          </el-date-picker>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractStatus!=4"
                      >
                        <el-form-item
                          label="合同状态:"
                          prop="discountStartTime"
                          label-width="140px"
                        >
                          <el-radio-group
                            :disabled="method==='view'"
                            v-model="inputForm.contractStatus"
                            style="width:100%;"
                          >
                            <el-radio :label=1>已签</el-radio>
                            <el-radio :label=0>未签</el-radio>
                          </el-radio-group>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="24"
                        v-if="inputForm.contractTypeId!=2"
                      >
                        <div>市场管理服务费信息</div>
                        <el-divider></el-divider>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId!=2"
                      >
                        <el-form-item
                          label="市场管理服务费单价(元/㎡.月):"
                          prop="discountStartTime"
                          label-width="220px"
                        >
                          <el-input
                            :disabled="method==='view'"
                            v-model="scgl.unitPriceId"
                            placeholder="请输入"
                            style="width:100%;"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId!=2"
                      >
                        <el-form-item
                          label="市场管理服务费税率:"
                          prop="discountStartTime"
                          label-width="220px"
                        >
                          <el-input
                            :disabled="method==='view'"
                            v-model="scgl.taxRateId"
                            placeholder="请输入"
                            style="width:100%;"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId!=2"
                      >
                        <el-form-item
                          label="市场管理服务费(含税元/年):"
                          prop="discountStartTime"
                          label-width="220px"
                        >
                          <el-input
                            :disabled="method==='view'"
                            v-model="scgl.incTaxTotalAmount"
                            placeholder="请输入"
                            style="width:100%;"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId!=2"
                      >
                        <el-form-item
                          label-width="220px"
                          label="市场管理服务费(无税元/年):"
                          prop="discountStartTime"
                        >
                          <el-input
                            :disabled="method==='view'"
                            v-model="scgl.noTaxTotalAmount"
                            placeholder="请输入"
                            style="width:100%;"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId!=2"
                      >
                        <el-form-item
                          label-width="220px"
                          label="市场管理服务费税金:"
                          prop="discountStartTime"
                        >
                          <el-input
                            :disabled="method==='view'"
                            v-model="scgl.taxAmount"
                            placeholder="请输入"
                            style="width:100%;"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col
                        :span="12"
                        v-if="inputForm.contractTypeId!=2"
                      >
                        <el-form-item
                          label-width="220px"
                          label="市场管理服务费合同总金额:"
                          prop="discountStartTime"
                        >
                          <el-input
                            :disabled="method==='view'"
                            v-model="scgl.totalAmount"
                            placeholder="请输入"
                            style="width:100%;"
                          ></el-input>
                        </el-form-item>
                      </el-col>
                      <template v-if="inputForm.contractTypeId!=1  && inputForm.contractTypeId!=2">
                        <el-col :span="24">
                          <div>租金信息</div>
                          <el-divider></el-divider>
                        </el-col>
                        <el-col :span="12">
                          <el-form-item
                            label-width="180px"
                            label="租金单价(元/㎡.月):"
                            prop="discountStartTime"
                          >
                            <el-input
                              :disabled="method==='view'"
                              v-model="zjxx.unitPriceId"
                              placeholder="请输入"
                              style="width:100%;"
                            ></el-input>
                          </el-form-item>
                        </el-col>
                        <el-col :span="12">
                          <el-form-item
                            label="税率分类:"
                            prop="discountStartTime"
                            label-width="180px"
                          >
                            <el-input
                              :disabled="method==='view'"
                              v-model="zjxx.taxRateId"
                              placeholder="请输入"
                              style="width:100%;"
                            ></el-input>
                          </el-form-item>
                        </el-col>
                        <el-col :span="12">
                          <el-form-item
                            label="税金:"
                            prop="discountStartTime"
                            label-width="180px"
                          >
                            <el-input
                              :disabled="method==='view'"
                              v-model="zjxx.taxAmount"
                              placeholder="请输入"
                              style="width:100%;"
                            ></el-input>
                          </el-form-item>
                        </el-col>
                        <el-col :span="12">
                          <el-form-item
                            label-width="180px"
                            label="含税合同金额(元/年):"
                            prop="discountStartTime"
                          >
                            <el-input
                              :disabled="method==='view'"
                              v-model="zjxx.incTaxTotalAmount"
                              placeholder="请输入"
                              style="width:100%;"
                            ></el-input>
                          </el-form-item>
                        </el-col>
                        <el-col :span="12">
                          <el-form-item
                            label-width="180px"
                            label="无税合同金额(元/年):"
                            prop="discountStartTime"
                          >
                            <el-input
                              :disabled="method==='view'"
                              v-model="zjxx.noTaxTotalAmount"
                              placeholder="请输入"
                              style="width:100%;"
                            ></el-input>
                          </el-form-item>
                        </el-col>
                        <el-col :span="12">
                          <el-form-item
                            label-width="180px"
                            label="租赁保证金(元):"
                          >
                            <el-input
                              :disabled="method==='view'"
                              v-model="zjxx.guaranteeAmount"
                              placeholder="请输入"
                              style="width:100%;"
                            ></el-input>
                          </el-form-item>
                        </el-col>
                        <el-col :span="12">
                          <el-form-item
                            label-width="180px"
                            label="合同总金额:"
                            prop="discountStartTime"
                          >
                            <el-input
                              :disabled="method==='view'"
                              v-model="zjxx.totalAmount"
                              placeholder="请输入"
                              style="width:100%;"
                            ></el-input>
                          </el-form-item>
                        </el-col>
                      </template>

                    </div>
                  </div>
                  <!--操作日志 -->
                  <div style="width:100%;float:left;">
                    <div style="width:100%;font-size:18px;border-bottom:1px double #ddd; line-height:40px; ">操作日志</div>
                    <div
                      class="block"
                      style="margin-top: 20px;"
                    >
                      <el-timeline>
                        <el-timeline-item
                          v-for="(activity, index) in logList"
                          :key="index"
                          icon="el-icon-more"
                          size="large"
                          :timestamp="activity.modifyContent"
                        >
                          {{activity.updateByName}} {{activity.updateDate}}
                        </el-timeline-item>
                      </el-timeline>
                    </div>
                  </div>
                </div>
              </el-tab-pane>
              <!--附件-->
              <el-tab-pane
                label="附件"
                name="second"
              >
                <el-table
                  :data="fileListData"
                  border
                  class="table"
                >

                  <el-table-column
                    prop="fileName"
                    show-overflow-tooltip
                    label="附件名称"
                  >
                  </el-table-column>
                  <el-table-column
                    prop="createByName"
                    label="创建人"
                  >
                  </el-table-column>
                  <el-table-column
                    prop="fileSize"
                    label="大小"
                  >
                  </el-table-column>
                  <el-table-column
                    prop="remarks"
                    show-overflow-tooltip
                    label="备注"
                  >
                  </el-table-column>
                  <el-table-column
                    prop="createDate"
                    label="创建时间"
                  >
                  </el-table-column>
                  <el-table-column
                    header-align="center"
                    align="center"
                    fixed="right"
                    width="200"
                    label="操作"
                  >
                    <template slot-scope="scope">
                      <el-button
                        type="text"
                        size="small"
                        @click="onDownLoad(scope.row)"
                      >下载</el-button>
                      <el-button
                        v-if="inputForm.contractStatus!=1"
                        type="text"
                        size="small"
                        @click="onDelFile(scope.row.id)"
                      >删除</el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </el-tab-pane>
            </el-tabs>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <!--续签-->
    <el-dialog
      title="续签合同"
      :visible.sync="dialogRenewal"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form :model="formR">
        <el-form-item
          label="续签日期"
          :label-width="formLabelWidth"
        >
          <el-date-picker
            v-model="formR.rentEndTime"
            prop="rentNewEndTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择续签日期"
            style="width:100%;"
            :picker-options="pickerOptions"
            :default-value="inputForm.rentEndTime"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div
        slot="footer"
        class="dialog-footer"
      >
        <el-button
          @click="dialogRenewal = false"
          icon="el-icon-circle-close"
        >取 消</el-button>
        <el-button
          type="primary"
          icon="el-icon-circle-check"
          @click="onRenewal()"
        >确 定</el-button>
      </div>
    </el-dialog>
    <!--已签-->
    <el-dialog
      title="签订合同"
      :visible.sync="dialogSigned"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form :model="formS">
        <el-form-item
          label="签订日期"
          :label-width="formLabelWidth"
        >
          <el-date-picker
            v-model="formS.signDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期"
            style="width:100%;"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div
        slot="footer"
        class="dialog-footer"
      >
        <el-button
          @click="dialogSigned = false"
          icon="el-icon-circle-close"
        >取 消</el-button>
        <el-button
          icon="el-icon-circle-check"
          type="primary"
          @click="onSigned()"
        >确 定</el-button>
      </div>
    </el-dialog>
    <!--终止-->
    <el-dialog
      title="终止合同"
      width='30%'
      :visible.sync="dialogTermination"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form :model="onTermination">
        <el-form-item
          label="终止日期"
          :label-width="formLabelWidth"
          required
        >
          <el-date-picker
            v-model="formT.stopDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期"
            style="width:100%;"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="终止原因"
          :label-width="formLabelWidth"
          required
        >
          <el-input
            type="textarea"
            v-model="formT.stopRemark"
            placeholder="请输入终止原因"
            :rows="4"
          ></el-input>
        </el-form-item>
      </el-form>
      <div
        slot="footer"
        class="dialog-footer"
      >
        <el-button
          @click="dialogTermination = false"
          icon="el-icon-circle-close"
        >取 消</el-button>
        <el-button
          icon="el-icon-circle-check"
          type="primary"
          @click="onTermination()"
        >确 定</el-button>
      </div>
    </el-dialog>
    <!--退保证金-->
    <el-dialog
      title="退保证金"
      width="25%"
      :visible.sync="dialogBackMoney"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form :model="formB">
        <el-form-item
          label="退款日期"
          :label-width="formLabelWidth"
        >
          <el-date-picker
            v-model="formB.refundTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期"
            style="width:100%;"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="退款单号"
          :label-width="formLabelWidth"
        >
          <el-input
            type="textarea"
            v-model="formB.refundNumber"
            placeholder="请输入单号"
            :rows="4"
          ></el-input>
        </el-form-item>
      </el-form>
      <div
        slot="footer"
        class="dialog-footer"
      >
        <el-button
          @click="dialogBackMoney = false"
          icon="el-icon-circle-clsoe"
        >取 消</el-button>
        <el-button
          icon="el-icon-circle-check"
          type="primary"
          @click="onBackMoney()"
        >确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  fetchList,
  getObj,
  addObj,
  putObj,
  delObj,
  getOperationLog,
  getFileList,
  downFile,
  putModifyObj,
  getContractTaxRateList,
  getContractType,
  getChargeUnitpPriceList,
  getCompanyList,
  getCompanyByPhone,
  fileLists,
  refund,
  selectType,
  relet
} from '@/api/market/contract/person'
import { OperationLog, getDicType } from '@/api/common.js'
import {
  getProjectType,
  getProjectStatus,
  getProjectpProperty
} from '@/api/market/estate/rmproject'
export default {
  data () {
    return {
      title: '',
      method: '',
      visible: false,
      dialogWidth: '50%',
      dialogRenewal: false,
      dialogSigned: false,
      dialogTermination: false,
      dialogBackMoney: false,
      loading: false,
      formLabelWidth: '80px',
      activeName: 'first',
      proBuildTypeList: [],
      contractTypeList: [{
        contractTypeName: '租赁合同',
        id: 0
      }, {
        contractTypeName: '销售合同',
        id: 1
      }],
      companyNameList: [],
      proCompanyList: [],
      rules: [],
      inputForm: {
        id: '',
        contractTypeId: '', //合同分类
        buildingType: '', //房产类型
        companyId: '', //公司id
        contractNumber: '', //合同编号
        taxpayerNumber: '', //纳税人识别号
        contactUserName: '', //联系人、联系方式
        contactUserPhone: '',
        rentEndTime: '',
        rentStartTime: '', //租赁开始日期
        discountEndTime: '',
        discountStartTime: '',
        contractTotalAmount: 0, //合同总金额
        contractStatus: 1,
        signDate: '', //签订日期
        ctContractChargeSummary: [], //各种费用  //费用类型(1.市场管理费 2.租金 3.租赁保证金)
        blChargeBillList: [], //合同账单
        ctContractFileList: [], //上传文件
        dateall: '',
        advertisingLocation: '',
        advertisingCount: '',
        advertisingLength: '',
        advertisingWidth: '',
        advertisingArea: '',
        advertisingType: '',
        advertisingUnitPrice: ''
      },
      pickerOptions: {
        disabledDate: this.disabledDate
      },
      //操作记录
      logList: [],
      //附件
      fileList: [],
      fileListData: [],
      formR: {
        id: '',
        rentEndTime: '',
      }, //续签
      formS: {
        id: '',
        signDate: '',
      }, //签订
      formT: {
        id: '',
        stopDate: '',
        stopRemark: '',
      }, //合同终止
      formB: {
        id: '',
        refundNumber: '',
        refundTime: '',
      }, //合同退保证金
      scgl: {
        chargeType: 1,
        unitPriceId: 0,
        taxRateId: 0,
        incTaxTotalAmount: 0,
        noTaxTotalAmount: 0,
        taxAmount: 0,
        totalAmount: 0,
      },
      zjxx: {
        chargeType: 2,
        unitPriceId: '',
        taxRateId: '',
        incTaxTotalAmount: 0,
        noTaxTotalAmount: 0,
        taxAmount: 0,
        totalAmount: 0,
        guaranteeAmount: 0,
        remarks: ''
      },
      advertisingTypeOption: [],
      // 列表页
      rmprojectLis: [],
      // 合同状态
      contractStatus: []
    }
  },
  created () {

  },
  filters: {
    GetcontractStatus (value, list) {
      let str = ''
      list.forEach(item => {
        if (value == item.value) {
          str = item.label
        }
      })
      return str
    }
  },
  methods: {
    xuqian () {
      this.$emit("openxuqian", this.inputForm.id)
      this.visible = false;
    },
    disabledDate (time) {
      let a = new Date(this.inputForm.rentEndTime)
      return time.getTime() < a.getTime()
    },
    init (method, id, ctContractProject) {
      this.activeName = 'first'
      getDicType('rm_project_buiding_type').then(res => {
        this.proBuildTypeList = res.data.data
      })
      //获取公司数据
      getCompanyByPhone().then(response => {
        if (response.data != null) {
          this.companyNameList = response.data.data;
        }
      })
      getDicType('contract_type').then(res => {
        this.contractTypeList = res.data.data
        this.contractTypeList.forEach((item, index) => {
          this.contractTypeList[index].value = parseInt(item.value)
        })
      })
      getDicType('advertising_type').then(res => {
        this.advertisingTypeOption = res.data.data
      })
      getDicType('contract_status').then(res => {
        this.contractStatus = res.data.data
      })
      this.method = method
      this.inputForm.id = id
      if (method === 'view') {
        this.title = '查看合同'
      }
      this.visible = true;
      //根据状态判断合同续签按钮是否显示隐藏

      //获取合同详情
      this.loading = false
      this.fileListData = []
      this.$nextTick(() => {
        // if (this.$refs.inputForm) {
        //   this.$refs.inputForm.resetFields()
        // }
        this.inputForm = this.$options.data().inputForm
        this.zjxx = this.$options.data().zjxx
        this.scgl = this.$options.data().scgl
        this.formR = {
          id: '',
          rentEndTime: '',
        }//续签
        this.formS = {
          id: '',
          signDate: '',
        } //签订
        this.formT = {
          id: '',
          stopDate: '',
          stopRemark: '',
        }//合同终止
        this.formB = {
          id: '',
          refundNumber: '',
          refundTime: '',
        } //合同退保证金
        if (method === 'view') { // 查看
          //获取合同信息
          getObj(id).then(response => {

            this.inputForm = response.data.data;
            // 暂时用不上查询，先注掉
            // selectType({}, this.inputForm.buildingType, 1).then((data) => {
            //   this.rmprojectList = data.data.data
            // })
            if (this.inputForm.rentStartTime && this.inputForm.rentEndTime) {
              this.inputForm.dateall = this.inputForm.rentStartTime + ' ~ ' + this.inputForm.rentEndTime
            }
            this.inputForm.ctContractProject = ctContractProject
            this.scgl.incTaxTotalAmount = 0
            this.scgl.noTaxTotalAmount = 0
            this.scgl.taxAmount = 0
            this.scgl.totalAmount = 0
            this.zjxx.incTaxTotalAmount = 0
            this.zjxx.noTaxTotalAmount = 0
            this.zjxx.taxAmount = 0
            this.zjxx.totalAmount = 0
            if (response.data.data.contractTypeId == 2) {
              this.inputForm.contractTotalAmount = response.data.data.ctContractChargeSummaryList[0].totalAmount
            }
            for (var i = 0; i < this.inputForm.ctContractChargeSummaryList.length; i++) {
              if (this.inputForm.ctContractChargeSummaryList[i].chargeType == 0) {
                this.scgl.unitPriceId = this.inputForm.ctContractChargeSummaryList[i].unitPriceId + '元/㎡/月'
                this.scgl.taxRateId = this.inputForm.ctContractChargeSummaryList[i].taxRateId + '%'
                this.scgl.incTaxTotalAmount = (this.scgl.incTaxTotalAmount + this.inputForm.ctContractChargeSummaryList[i].incTaxTotalAmount).toFixed(2)
                this.scgl.noTaxTotalAmount = (this.scgl.noTaxTotalAmount + this.inputForm.ctContractChargeSummaryList[i].noTaxTotalAmount).toFixed(2)
                this.scgl.taxAmount = (this.scgl.taxAmount + this.inputForm.ctContractChargeSummaryList[i].taxAmount).toFixed(2)
                this.scgl.totalAmount = (this.scgl.totalAmount + this.inputForm.ctContractChargeSummaryList[i].totalAmount).toFixed(2)
              }
              if (this.inputForm.ctContractChargeSummaryList[i].chargeType == 1) {
                this.zjxx.unitPriceId = this.inputForm.ctContractChargeSummaryList[i].unitPriceId + '元/㎡/月'
                this.zjxx.taxRateId = this.inputForm.ctContractChargeSummaryList[i].taxRateId + '%'
                this.zjxx.guaranteeAmount = (this.inputForm.ctContractChargeSummaryList[i].guaranteeAmount).toFixed(2)
                this.zjxx.incTaxTotalAmount = (this.zjxx.incTaxTotalAmount + this.inputForm.ctContractChargeSummaryList[i].incTaxTotalAmount).toFixed(2)
                this.zjxx.noTaxTotalAmount = (this.zjxx.noTaxTotalAmount + this.inputForm.ctContractChargeSummaryList[i].noTaxTotalAmount).toFixed(2)
                this.zjxx.taxAmount = (this.zjxx.taxAmount + this.inputForm.ctContractChargeSummaryList[i].taxAmount).toFixed(2)
                this.zjxx.totalAmount = (this.zjxx.totalAmount + this.inputForm.ctContractChargeSummaryList[i].totalAmount).toFixed(2)
              }
            }
          })
        }
      })
      //获取操作日志
      let url = '/config/sysoperationlog/' + this.inputForm.id + '/5'
      OperationLog(url).then(response => {
        this.logList = response.data.data
      })
    },
    //获取附件
    handleClick (tab, event) {
      //tab切换附件,加载数据
      if (tab.name == 'second') {
        //this.getFileLists();
        fileLists(this.inputForm.id).then(res => {
          this.fileListData = res.data.data
        })
        // this.fileList = this.inputForm.sysUploadFileList;
      }
    },
    //续签
    onRenewal () {
      if (this.inputForm.id == "") {
        this.$notify.error('未获取到合同ID值')
        return;
      }
      if (!this.formR.rentEndTime) {
        this.$notify.error('请选择续租日期')
        return
      }
      if (this.inputForm.rentEndTime > this.formR.rentEndTime) {
        this.$notify.error('续租日期必须大于' + this.inputForm.rentEndTime)
        return
      }
      this.formR.id = this.inputForm.id;
      //点击续签后，根据合同到期日期，顺延一天为续签合同的默认开始日期
      relet(this.formR).then(response => {
        if (response.data.data) {
          this.$message.success('操作成功')
          //刷新列表
          //getObj(this.inputForm.id).then(response => {
          //  this.inputForm = response.data.data;
          //})
        } else {
          this.$notify.error('操作失败')
        }
      })
      this.dialogRenewal = false;
    },
    //已签
    onSigned () {
      if (this.inputForm.id == "") {
        this.$notify.error('未获取到合同ID值')
        return;
      }
      if (!this.formS.signDate) {
        this.$message.warning('请选择已签合同日期')
        return
      }
      this.formS.id = this.inputForm.id;
      this.formS.contractStatus = 1
      this.formS.ctContractProjectList = this.inputForm.ctContractProjectList
      //调用接口 合同为未签状态时，出现已签按钮，可对合同进行状态修改,点击“已签”后，弹出签订日期输入框进行日期选择输入
      putModifyObj(this.formS).then(response => {
        if (response.data.data) {
          this.visible = true;
          this.$message.success('操作成功')
        } else {
          this.$notify.error('操作失败')
        }
      })
      this.dialogSigned = false;
    },
    //终止
    onTermination () {
      if (this.inputForm.id == "") {
        this.$notify.error('未获取到合同ID值')
        return;
      }
      if (!this.formT.stopDate) {
        this.$message.warning('请选择终止日期')
        return
      }
      if (!this.formT.stopRemark) {
        this.$message.warning('请输入终止原因')
        return
      }
      this.formT.id = this.inputForm.id;
      this.formT.contractStatus = 4
      this.formT.ctContractProjectList = this.inputForm.ctContractProjectList
      putModifyObj(this.formT).then(response => {
        if (response.data.data) {
          this.visible = false
          this.$message.success('操作成功')
          this.$emit('refreshDataList')
        } else {
          this.$notify.error('操作失败')
        }
      })
      this.dialogTermination = false;
    },
    //退保证金
    onBackMoney () {
      if (this.inputForm.id == "") {
        this.$notify.error('未获取到合同ID值')
        return;
      }
      if (!this.formB.refundNumber) {
        this.$notify.error('请输入退款单号')
        return;
      }
      if (!this.formB.refundTime) {
        this.$notify.error('请选择退款时间')
        return;
      }
      this.formB.id = this.inputForm.id;
      this.formB.ctContractProjectList = this.inputForm.ctContractProjectList
      refund(this.formB).then(response => {
        if (response.data.data) {
          this.visible = false
          this.$message.success('操作成功')
          this.$emit('refreshDataList')
        } else {
          this.$notify.error('操作失败')
        }
      })
      this.dialogBackMoney = false;
    },
    //加载附件列表
    getFileLists () {
      getFileList().then(response => {
        if (response.data != null) {
          this.fileList = response.data.data.records;
        }
      })
    },
    //下载附件
    onDownLoad: function (row) {
      if (row.filePath) {
        let link = document.createElement('a')
        link.href = row.filePath
        link.target = '_blank'
        let filename = row.filename
        link.download = decodeURI(row.filename)
        document.body.appendChild(link)
        link.click()
        document.body.removeChild(link)
      } else {
        this.$message.error("未找到文件路径！！！！")
      }
    },
    //删除附件
    onDelFile: function (id) {
      this.$confirm("此操作将删除该附件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        deleteFile(id).then(() => {
          this.getFileLists();
          this.$notify.success('删除成功')
        }).catch(() => {
          this.$notify.error('删除失败')
        });
      });
    },
  }
}
</script>
